<?php
/**
 * Created by PhpStorm.
 * User: PHP
 * Date: 2021/6/17
 * Time: 15:35
 */
namespace Hlcreation\Services;
use Hlcreation\Basic\Helper;
use App\Exceptions\ApiException as HOException;
use Illuminate\Support\Facades\DB;


class AnnouncementServer
{

    //添加公告
    public function annount_send($arr){
        $url = "http://platform.com/platformapi/notice/crate";

        try {
            $arr_json= json_encode($arr);
            //dd($arr_json);
            $arr_encode=base64_encode($arr_json);
            //dd($arr_encode);
            //dd($arr);
            $data=Helper::httpPost($url,$arr_encode);
            //dd($data);
            if(isset($data['code'])){
                if($data['code']==200){
                    return true;
                }else{
                    throw new HOException($data['msg']);
                }
            }else{
                throw new HOException('公告异常');
            }
        } catch (\Exception $e) {
            throw new HOException($e->getMessage());
        }



    }



    //编辑公告
    public function  annount_edit($arr){
        $url = "http://platform.com/platformapi/notice/edit";
        DB::beginTransaction();
        try {
            $arr_json= json_encode($arr);
            $arr_encode=base64_encode($arr_json);

            $res=Helper::httpPost($url,$arr_encode);
          //  dd($res);
            if(isset($res['code'])){
                if($res['code']==200){
                    return true;
                }else{
                    throw new HOException($res['msg']);
                }
            }else{
                throw new HOException('公告异常');
            }
        } catch (\Exception $e) {
            throw new HOException($e->getMessage());
        }
    }



    //删除公告
    public function annount_del($id){

        $url = "http://platform.com/platformapi/notice/delete";
        DB::beginTransaction();
        try {
            $arr_json= json_encode($id);
            $arr_encode=base64_encode($arr_json);

            $res=Helper::httpPost($url,$arr_encode);
            dd($res);
            if(isset($res['code'])){
                if($res['code']==200){
                    return true;
                }else{
                    throw new HOException($res['msg']);
                }
            }else{
                throw new HOException('公告异常');
            }
        } catch (\Exception $e) {
            throw new HOException($e->getMessage());
        }
    }





















}
